package com.webbei.custom.action;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import com.webbei.custom.service.CustomSer;
import com.webbei.pojo.PicInfor;

public class Preview {

	private CustomSer cs;
	private String bgPic;
	private String pi;
	private String filename;
	private int swidth;

	public void setCs(CustomSer cs) {
		this.cs = cs;
	}
	
	public String execute(){
		//到时候判断用户是否存在，若存在并保存，将其所有文件保存到用户文件夹下，一个定制一个文件夹
		JSONArray ja = JSONArray.fromObject(pi);
		List<PicInfor> pif = new ArrayList<PicInfor>();
		for(int i=0;i<ja.size();i++){
			PicInfor picinfor  =new PicInfor();
			picinfor.setPicUrl(ja.getJSONObject(i).getString("picurl").substring(29));
			picinfor.setWidth(Integer.valueOf(ja.getJSONObject(i).getString("width")));
			picinfor.setHeight(Integer.valueOf(ja.getJSONObject(i).getString("height")));
			picinfor.setLeft(Integer.valueOf(ja.getJSONObject(i).getString("left")));
			picinfor.setTop(Integer.valueOf(ja.getJSONObject(i).getString("top")));
			pif.add(picinfor);
		}
		bgPic = bgPic.substring(29);
		filename = cs.drawPic(bgPic, pif);
		return "success";
	}

	public String getFilename() {
		return filename;
	}

	public void setBgPic(String bgPic) {
		this.bgPic = bgPic;
	}

	public void setPi(String pi) {
		this.pi = pi;
	}

	public void setSwidth(int swidth) {
		this.swidth = swidth;
	}
	
}
